#include "PackageTool.h"
uint8_t test_data[366] = {
    1,
    123,
    97,
    210,
    2,
    150,
    73,
    21,
    205,
    91,
    7,
    218,
    15,
    73,
    64,
    74,
    216,
    18,
    77,
    251,
    33,
    9,
    64,
    0,
    128,
    0,
    0,
    0,
    128,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    128,
    128,
    13,
    0,
    0,
    0,
    72,
    101,
    108,
    108,
    111,
    44,
    32,
    119,
    111,
    114,
    108,
    100,
    33,
    210,
    2,
    150,
    73,
    21,
    205,
    91,
    7,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    3,
    0,
    0,
    0,
    1,
    0,
    1,
    3,
    0,
    0,
    0,
    1,
    2,
    3,
    3,
    0,
    0,
    0,
    97,
    98,
    99,
    2,
    0,
    0,
    0,
    2,
    0,
    0,
    0,
    1,
    0,
    0,
    0,
    4,
    0,
    0,
    0,
    3,
    0,
    0,
    0,
    2,
    0,
    0,
    0,
    218,
    15,
    73,
    64,
    84,
    248,
    45,
    64,
    2,
    0,
    0,
    0,
    74,
    216,
    18,
    77,
    251,
    33,
    9,
    64,
    1,
    127,
    66,
    135,
    10,
    191,
    5,
    64,
    3,
    0,
    0,
    0,
    0,
    128,
    1,
    128,
    255,
    127,
    3,
    0,
    0,
    0,
    0,
    0,
    0,
    128,
    1,
    0,
    0,
    128,
    255,
    255,
    255,
    127,
    3,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    128,
    1,
    0,
    0,
    0,
    0,
    0,
    0,
    128,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    127,
    3,
    0,
    0,
    0,
    128,
    129,
    127,
    2,
    0,
    0,
    0,
    13,
    0,
    0,
    0,
    72,
    101,
    108,
    108,
    111,
    44,
    32,
    119,
    111,
    114,
    108,
    100,
    33,
    18,
    0,
    0,
    0,
    228,
    189,
    160,
    229,
    165,
    189,
    239,
    188,
    140,
    228,
    184,
    150,
    231,
    149,
    140,
    239,
    188,
    129,
    2,
    0,
    0,
    0,
    6,
    0,
    0,
    0,
    5,
    0,
    0,
    0,
    8,
    0,
    0,
    0,
    7,
    0,
    0,
    0,
    3,
    0,
    0,
    0,
    255,
    255,
    254,
    255,
    0,
    0,
    3,
    0,
    0,
    0,
    255,
    255,
    255,
    255,
    254,
    255,
    255,
    255,
    0,
    0,
    0,
    0,
    3,
    0,
    0,
    0,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    254,
    255,
    255,
    255,
    255,
    255,
    255,
    255,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    3,
    0,
    0,
    0,
    255,
    254,
    0,
};
int main()
{
    struct ros_time tt1, tt2;

    PackageTool pl;
    pl.put_bool(true);
    pl.put_byte(123);
    pl.put_char('a');
    tt1.nsecs = 123456789;
    tt1.secs = 1234567890;
    pl.put_duration(tt1);
    pl.put_float32(3.1415926);
    pl.put_float64(3.1415926);
    pl.put_int16(-32768);
    pl.put_int32(-2147483648);
    pl.put_int64(-9223372036854775808);
    pl.put_int8(-128);
    printf("offset = %d\n", pl.offset());
    pl.put_string("Hello, world!");
    tt1.nsecs = 123456789;
    tt1.secs = 1234567890;
    pl.put_time(tt1);
    pl.put_uint16(65535);
    pl.put_uint32(4294967295);
    pl.put_uint64(18446744073709551615);
    pl.put_uint8(255);

    pl.put_bool_array({true, false, true});
    pl.put_byte_array({1, 2, 3});
    pl.put_char_array({'a', 'b', 'c'});
    tt1.nsecs = 1;
    tt1.secs = 2;
    tt2.nsecs = 3;
    tt2.secs = 4;
    pl.put_duration_array({tt1, tt2});
    pl.put_float32_array({3.1415926, 2.7182818});
    pl.put_float64_array({3.1415926, 2.7182818});
    pl.put_int16_array({ -32768, -32767, 32767 });
    pl.put_int32_array({ -2147483648, -2147483647, 2147483647 });
    pl.put_int64_array({ -9223372036854775808, -9223372036854775807, 9223372036854775807 });
    pl.put_int8_array({ -128, -127, 127 });
    pl.put_string_array({ "Hello, world!", "你好，世界！" });
    tt1.nsecs = 5;
    tt1.secs = 6;
    tt2.nsecs = 7;
    tt2.secs = 8;
    pl.put_time_array({tt1, tt2});
    pl.put_uint16_array({ 65535, 65534, 0 });
    pl.put_uint32_array({ 4294967295, 4294967294, 0 });
    pl.put_uint64_array({ 18446744073709551615, 18446744073709551614, 0 });
    pl.put_uint8_array({ 255, 254, 0 });

    pl.offset(0);
    auto b = pl.get_bool();
    if(b!= true)
    {
        printf("!!! %d != %d\n", b, true);
        exit(0);
    }
    auto b1 = pl.get_byte();
    if(b1 != 123)
    {
        printf("!!! %d != %d\n", b1, 123);
        exit(0);
    }
    auto c = pl.get_char();
    if(c != 'a')
    {
        printf("!!! %c != %c\n", c, 'a');
        exit(0);
    }
    tt1 = pl.get_duration();
    if(tt1.nsecs != 123456789 || tt1.secs != 1234567890)
    {
        printf("!!! %d , %d == %d, %d\n", tt1.nsecs, tt1.secs, 123456789, 1234567890);
        exit(0);
    }
    auto f32 = pl.get_float32();
    if(f32 != 3.1415926)
    {
        printf("!!! %f != %f\n", f32, 3.1415926);
        // exit(0);
    }
    auto f64 = pl.get_float64();
    if(f64 != 3.1415926)
    {
        printf("!!! %f != %f\n", f64, 3.1415926);
        exit(0);
    }
    auto i16 = pl.get_int16();
    if(i16 != -32768)
    {
        printf("!!! %d != %d\n", i16, -32768);
        exit(0);
    }
    auto i32 = pl.get_int32();
    if(i32 != -2147483648)
    {
        printf("!!! %d != %d\n", i32, -2147483648);
        exit(0);
    }
    auto i64 = pl.get_int64();
    if(i64 != -9223372036854775808)
    {
        printf("!!! %lld != %lld\n", i64, -9223372036854775808);
        exit(0);
    }
    auto i8 = pl.get_int8();
    if(i8 != -128)
    {
        printf("!!! %d != %d\n", i8, -128);
        exit(0);
    }
    auto s = pl.get_string();
    if(s != "Hello, world!")
    {
        printf("!!! %s != %s\n", s.c_str(), "Hello, world!");
        exit(0);
    }
    tt1 = pl.get_time();
    if(tt1.nsecs != 123456789 || tt1.secs != 1234567890)
    {
        printf("!!! %d , %d == %d, %d\n", tt1.nsecs, tt1.secs, 123456789, 1234567890);
        exit(0);
    }
    auto u16 = pl.get_uint16();
    if(u16 != 65535)
    {
        printf("!!! %d != %d\n", u16, 65535);
        exit(0);
    }
    auto u32 = pl.get_uint32();
    if(u32 != 4294967295)
    {
        printf("!!! %d != %d\n", u32, 4294967295);
        exit(0);
    }
    auto u64 = pl.get_uint64();
    if(u64 != 18446744073709551615)
    {
        printf("!!! %lld != %lld\n", u64, 18446744073709551615);
        exit(0);
    }
    auto u8 = pl.get_uint8();
    if(u8 != 255)
    {
        printf("!!! %d != %d\n", u8, 255);
        exit(0);
    }

    auto ba = pl.get_bool_array();
    if(ba[0] != true || ba[1] != false || ba[2] != true)
    {
        printf("!!! %d , %d , %d == %d, %d, %d\n", ba[0], ba[1], ba[2], true, false, true);
        exit(0);
    }
    auto ba1 = pl.get_byte_array();
    if(ba1[0] != 1 || ba1[1] != 2 || ba1[2] != 3)
    {
        printf("!!! %d , %d , %d == %d, %d, %d\n", ba1[0], ba1[1], ba1[2], 1, 2, 3);
        exit(0);
    }
    auto ca = pl.get_char_array();
    if(ca[0] != 'a' || ca[1] != 'b' || ca[2] != 'c')
    {
        printf("!!! %c , %c , %c == %c, %c, %c\n", ca[0], ca[1], ca[2], 'a', 'b', 'c');
        exit(0);
    }
    auto da = pl.get_duration_array();
    if(da[0].nsecs != 1 || da[0].secs != 2 || da[1].nsecs != 3 || da[1].secs != 4)
    {
        printf("!!! %d , %d , %d , %d == %d, %d, %d, %d\n", da[0].nsecs, da[0].secs, da[1].nsecs, da[1].secs, 1, 2, 3, 4);
        exit(0);
    }
    auto fa32 = pl.get_float32_array();
    if(fa32[0] != 3.1415926 || fa32[1] != 2.7182818)
    {
        printf("!!! %f , %f == %f, %f\n", fa32[0], fa32[1], 3.1415926, 2.7182818);
        // exit(0);
    }
    auto fa64 = pl.get_float64_array();
    if(fa64[0] != 3.1415926 || fa64[1] != 2.7182818)
    {
        printf("!!! %f , %f == %f, %f\n", fa64[0], fa64[1], 3.1415926, 2.7182818);
        exit(0);
    }
    auto ia16 = pl.get_int16_array();
    if(ia16[0] != -32768 || ia16[1] != -32767 || ia16[2] != 32767)
    {
        printf("!!! %d , %d , %d == %d, %d, %d\n", ia16[0], ia16[1], ia16[2], -32768, -32767, 32767);
        exit(0);
    }
    auto ia32 = pl.get_int32_array();
    if(ia32[0] != -2147483648 || ia32[1] != -2147483647 || ia32[2] != 2147483647)
    {
        printf("!!! %d , %d , %d == %d, %d, %d\n", ia32[0], ia32[1], ia32[2], -2147483648, -2147483647, 2147483647);
        exit(0);
    }
    auto ia64 = pl.get_int64_array();
    if(ia64[0] != -9223372036854775808 || ia64[1] != -9223372036854775807 || ia64[2] != 9223372036854775807)
    {
        printf("!!! %lld , %lld , %lld == %lld, %lld, %lld\n", ia64[0], ia64[1], ia64[2], -9223372036854775808, -9223372036854775807, 9223372036854775807);
        exit(0);
    }

    auto ia8 = pl.get_int8_array();
    if(ia8[0] != -128 || ia8[1] != -127 || ia8[2] != 127)
    {
        printf("!!! %d , %d , %d == %d, %d, %d\n", ia8[0], ia8[1], ia8[2], -128, -127, 127);
        exit(0);
    }
    
    auto sa = pl.get_string_array();
    if(sa[0] != "Hello, world!" || sa[1] != "你好，世界！")
    {
        printf("!!! %s , %s == %s, %s\n", sa[0].c_str(), sa[1].c_str(), "Hello, world!", "你好，世界！");
        exit(0);
    }
    auto ta = pl.get_time_array();
    if(ta[0].nsecs != 5 || ta[0].secs != 6 || ta[1].nsecs != 7 || ta[1].secs != 8)
    {
        printf("!!! %d , %d , %d , %d == %d, %d, %d, %d\n", ta[0].nsecs, ta[0].secs, ta[1].nsecs, ta[1].secs, 5, 6, 7, 8);
        exit(0);
    }

    auto ua16 = pl.get_uint16_array();
    if(ua16[0] != 65535 || ua16[1] != 65534 || ua16[2] != 0)
    {
        printf("!!! %d , %d , %d == %d, %d, %d\n", ua16[0], ua16[1], ua16[2], 65535, 65534, 0);
        exit(0);
    }
    auto ua32 = pl.get_uint32_array();
    if(ua32[0] != 4294967295 || ua32[1] != 4294967294 || ua32[2] != 0)
    {
        printf("!!! %d , %d , %d == %d, %d, %d\n", ua32[0], ua32[1], ua32[2], 4294967295, 4294967294, 0);
        exit(0);
    }
    auto ua64 = pl.get_uint64_array();
    if(ua64[0] != 18446744073709551615 || ua64[1] != 18446744073709551614 || ua64[2] != 0)
    {
        printf("!!! %lld , %lld , %lld == %lld, %lld, %lld\n", ua64[0], ua64[1], ua64[2], 18446744073709551615, 18446744073709551614, 0);
        exit(0);
    }
    auto ua8 = pl.get_uint8_array();
    if(ua8[0] != 255 || ua8[1] != 254 || ua8[2] != 0)
    {
        printf("!!! %d , %d , %d == %d, %d, %d\n", ua8[0], ua8[1], ua8[2], 255, 254, 0);
        exit(0);
    }
    printf("--------------------- %d\n",pl.offset());
    for (int i = 0; i < pl.offset(); i++)
    {
        printf("!!! %d , %d == %d\n", i, test_data[i], pl.data()[i]);
        if (test_data[i] != pl.data()[i] && i>5)
        {
            exit(0);
        }
    }
    printf("ok\n");
    return 0;
}

// g++ pt_test.cpp && ./a.out